﻿/*
// +----------------------------------------------------------------------------+
// |                                                                            |
// |  Copyright (1999-2010) by Actify, Inc.                                     |
// |                                                                            |
// |  This program is proprietary with Actify, Inc., and is not to              |
// |  be reproduced or transmitted in any form or by any means or used in any   |
// |  manner except as authorized in writing by Actify, Inc.                    |
// |                                                                            |
// +----------------------------------------------------------------------------+
// |                                                                            |
// |   File Name : TreeItem.cs                                                  |
// |  Written By : Clay Tornquist                                               |
// |        Date : Feb 09 2010                                                  |
// | Description :                                                              |
// |                                                                            |
// +----------------------------------------------------------------------------+
// |                                                                            |
// | Notes:                                                                     |
// |                                                                            |
// +----------------------------------------------------------------------------+

	Changes:
		[2010-02-09 CMT] - Initial implementation.

*/
using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SpinFireSL
{
	/// <summary>
	/// Object that represents the information displayed in the tree
	/// </summary>
	public class TreeItem
	{
		#region Definitions

		/// <summary>
		/// The type of information for this tree item
		/// </summary>
		internal enum TreeItemType { RootNode, Geometry, Markup, View }

		#endregion

		#region Attributes

		private ObservableCollection<TreeItem> childItemsValue = new ObservableCollection<TreeItem>();
		private ResourceHelper _rh = new ResourceHelper();
		private bool _visible = true;
		private const string _invisibleColor = "#00000000";
		private const string _hiddenLineColor = "#FF515151";

		#endregion

		#region Constructor

		/// <summary>
		/// Object that represents the information displayed in the tree
		/// </summary>
		/// <param name="title">the title displayed in the tree</param>
		/// <param name="entitycolor">the entity color in the model</param>
		/// <param name="path">the path to get to this object (geometry data)</param>
		/// <param name="itemType">the tree item type</param>
		internal TreeItem(string title, Color entitycolor, string path, TreeItemType itemType)
		{
			Title = title;
			Path = path;
			ItemType = itemType;
			Color = entitycolor;
			Highlighted = false;
		}

		#endregion

		#region Public Members

		/// <summary>
		/// The title displayed to the user
		/// </summary>
		public string Title { get; set; }


		/// <summary>
		/// The entity color
		/// </summary>
		public string EntityColor { get { return Visible ? Color.ToString() : _invisibleColor; } }
		// The hidden line color
		public string HiddenLineColor { get { return Visible ? _invisibleColor : _hiddenLineColor; } }

		public Color Color { get; set; }

		/// <summary>
		/// True if highlighted
		/// </summary>
		public bool Highlighted { get; set; }

		public bool Visible 
		{
			get
			{
				bool ret = false;
				if (ChildItems.Count == 0)
				{
					ret = _visible;
				}
				else
				{
					foreach (TreeItem ti in ChildItems)
					{
						if (ti.Visible)
						{
							ret = true;
							break;
						}
					}
				}
				return ret;
			}
			set
			{
				_visible = value;
				foreach (TreeItem c in ChildItems)
				{
					c.Visible = _visible;
				}
			}
		}
		public System.Windows.Media.Imaging.BitmapImage ShowHideImage 
		{ 
			get 
			{ 
				return Visible ?  _rh.GetBitmap("Images/show 256x256.png") : _rh.GetBitmap("Images/hide 256x256.png"); 
			} 
		}
		/// <summary>
		/// The child items for this 
		/// </summary>
		public ObservableCollection<TreeItem> ChildItems
		{
			get
			{
				return childItemsValue;
			}
			set
			{
				childItemsValue = value;
			}
		}

		#endregion

		#region Internal Members

		internal string Path { get; set; }

		internal TreeItemType ItemType { get; set; }

		internal object Tag { get; set; }

		#endregion

	}
}
